# AUTHOR: DING
# -*- codeing = utf-8 -*-
# @Time: 2024/2/22 16:50
# @Author: 86139
# @Site: 
# @File: 12-convLayer.py
# @Software: PyCharm
# tensorboard --logdir=pytorch/logs --port=6007
import torch
import torch.nn as nn
import torchvision
from torch.nn import Conv2d
from torch.utils.data import DataLoader
from torch.utils.tensorboard import SummaryWriter

dataset = torchvision.datasets.CIFAR10("./dataset", train=False, transform=torchvision.transforms.ToTensor(),
                                       download=True)
dataloader = DataLoader(dataset=dataset, batch_size=64, drop_last=True)


class NNModule(nn.Module):
    def __init__(self):
        super().__init__()
        # 卷积核kernel是随机的
        self.conv1 = Conv2d(in_channels=3, out_channels=6, kernel_size=(3, 3), stride=(1, 1), padding=0)

    def forward(self, x):
        x = self.conv1(x)
        return x


nnmodule = NNModule()
print(nnmodule)

writer = SummaryWriter("./logs")
step = 0
for data in dataloader:
    imgs, targets = data
    output = nnmodule(imgs)
    # print(imgs.shape)  # [64,3,32,32]
    # print(output.shape) # [64,6,30,30]
    writer.add_images("input", imgs, step)
    output = torch.reshape(output, ([-1, 3, 30, 30]))
    writer.add_images("output", output, step)
    step += 1
writer.close()
